package com.hzdesk.media.koreabatchmatvector.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.hzdesk.media.koreabatchmatvector.R;
import com.hzdesk.media.koreabatchmatvector.inter.OnMouseListItemClickListener;

import java.util.List;

/**
 * Created by Administrator on 2018/7/25.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 */

public class ShowLogeAdapter extends RecyclerView.Adapter<ShowLogeAdapter.ShowLogeViewHoder> {
    private List<String> mBean;
    private Context mContext;

    public void setmOnMouseListItemClickListener(OnMouseListItemClickListener mOnMouseListItemClickListener) {
        this.mOnMouseListItemClickListener = mOnMouseListItemClickListener;
    }

    private OnMouseListItemClickListener mOnMouseListItemClickListener = null;
    public ShowLogeAdapter(Context tContext) {
        mContext = tContext;
    }

    @Override
    public ShowLogeAdapter.ShowLogeViewHoder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.show_loge_item,parent,false);
        ShowLogeViewHoder showLogeViewHoder = new ShowLogeViewHoder(view);
        return showLogeViewHoder;
    }

    @Override
    public void onBindViewHolder(ShowLogeAdapter.ShowLogeViewHoder holder, final int position) {
        Glide.with(mContext).load(mBean.get(position)).into(holder.iv_show_logo);
        holder.rl_logo.setOnHoverListener(onHoverListener);
        holder.rl_logo.setOnFocusChangeListener(onFocusChangeListener);
        holder.rl_logo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(mOnMouseListItemClickListener != null){
                    mOnMouseListItemClickListener.OnItemClick(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mBean == null?0:mBean.size();
    }

    public void AddDate(List<String> mlist){
        mBean = mlist;
        notifyDataSetChanged();
    }



    class ShowLogeViewHoder extends RecyclerView.ViewHolder {
        private final ImageView iv_show_logo;
        private final RelativeLayout rl_logo;

        public ShowLogeViewHoder(View itemView) {
            super(itemView);
            iv_show_logo = itemView.findViewById(R.id.show_loge_item_iv_show_logo);
            rl_logo = itemView.findViewById(R.id.show_loge_item_rl_logo);
        }
    }
    private View.OnHoverListener onHoverListener = new View.OnHoverListener() {
        @Override
        public boolean onHover(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_HOVER_ENTER:
                    v.requestFocus();
                    v.requestFocusFromTouch();
                    break;
                case MotionEvent.ACTION_HOVER_EXIT:
                    break;
                case MotionEvent.ACTION_HOVER_MOVE:
                    break;
            }
            return false;
        }
    };

    private View.OnFocusChangeListener onFocusChangeListener=new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            RelativeLayout linearLayout= (RelativeLayout) v;
            if (hasFocus){
                linearLayout.setBackgroundResource(R.drawable.color_picker_bg_light_logo);
            }else {
                linearLayout.setBackgroundResource(R.drawable.color_picker_bg_logo);

            }

        }
    };
}
